<script>
export default {
  name: 'UiUploadSeparateProvide',
  provide () {
    return {
      UiUploadSeparateProvide: this
    }
  },
  props: {
    editable: {
      type: Boolean,
      default: true
    },
    disabled: {
      type: Boolean
    },
    value: {
      type: [Array, String],
      default: undefined
    },
    accept: {
      type: String,
      default: undefined
    },
    autoUpload: {
      type: Boolean,
      default: true
    },
    uploadMethod: {
      type: Function
    },
    multiple: {
      type: Boolean,
      default: false
    },
    limitCount: {
      type: Number,
      default: undefined
    },
    limitSize: {
      type: Number,
      default: undefined
    }
  },
  data() {
    return {
      fileList: []
    }
  },
  computed: {
    innerValue: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit('input', val)
      }
    },
    innerDisabled() {
      if (this.disabled) {
        return true
      }
      if (this.limitCount) {
        if (this.fileList.length >= this.limitCount) {
          return true
        }
      }
      return false
    }
  },
  methods: {
    handleFileListChange({ fileList }) {
      this.fileList = fileList
    },
    handleUploadSuccess(evt) {
      this.$emit('upload-success', evt)
    },
    removeFile (fileId) {
      this._removeFile && this._removeFile(fileId)
    }
  },
  render () {
    return this.$slots.default
  }
}
</script>
<style lang="less">
</style>
